//
//  LHCSecondViewController.m
//  UIimageViewDemo
//
//  Created by lihongcheng on 16/4/13.
//  Copyright © 2016年 lihongcheng. All rights reserved.
//

#import "LHCSecondViewController.h"


#define W    [[UIScreen mainScreen] bounds].size.width
#define H    [[UIScreen mainScreen] bounds].size.height



@interface LHCSecondViewController ()<UITextFieldDelegate>



@end

@implementation LHCSecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"图片编辑";
    [self createShowImageView];
}

-(void)createShowImageView
{
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClick:)];
    self.navigationItem.leftBarButtonItem = backBtn;
    
    UIBarButtonItem *saveBtn = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveBtnClick:)];
    self.navigationItem.rightBarButtonItem = saveBtn;
    
    UITextField *titleField = [[UITextField alloc] initWithFrame:CGRectMake(0, 64, W, 44)];
    titleField.placeholder = @"请输入图片名称";
    titleField.delegate = self;
    titleField.tag = 200;
    titleField.returnKeyType = UIReturnKeyDone;
    [self.view addSubview:titleField];
    
    UIImageView *showImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64+44, W, H)];
    showImage.image = self.imageName;
    showImage.userInteractionEnabled = YES;

    [self.view addSubview:showImage];
    
    //创建点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [showImage addGestureRecognizer:tap];

}

-(void)tapClick:(UITapGestureRecognizer *)tap
{
    UITextField *tField = (UITextField *)[self.view viewWithTag:200];
    [tField resignFirstResponder];
}

-(void)saveBtnClick:(UIBarButtonItem *)btn
{
    UITextField *tfield = (UITextField *)[self.view viewWithTag:200];
    [self.delegate setImageTitle:tfield.text];
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)backBtnClick:(UIBarButtonItem *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
